﻿function showfDiv(obj, content, width) {
    var pos = getPosition(obj);
    var objDiv = document.getElementById("s_id");
    if (objDiv == null) {
        objDiv = document.createElement("div");
        objDiv.id = "s_id";
    }
    objDiv.className = "selectStyle";
    objDiv.style.position = "absolute";
    var tempheight = pos.y;
    var tempwidth1, tempheight1;
    var windowwidth = document.body.clientWidth;

    var isIE5 = (navigator.appVersion.indexOf("MSIE 5") > 0) || (navigator.appVersion.indexOf("MSIE") > 0 && parseInt(navigator.appVersion) > 4);
    var isIE55 = (navigator.appVersion.indexOf("MSIE 5.5") > 0);
    var isIE6 = (navigator.appVersion.indexOf("MSIE 6") > 0);
    var isIE7 = (navigator.appVersion.indexOf("MSIE 7") > 0);

    if (isIE5 || isIE55 || isIE6 || isIE7) { var tempwidth = pos.x + 305; } else { var tempwidth = pos.x + 312; }
    objDiv.style.width = width + "px";
    objDiv.innerHTML = content;
    if (tempwidth > windowwidth) {
        tempwidth1 = tempwidth - windowwidth
        objDiv.style.left = (pos.x - tempwidth1) + "px";
    }
    else {
        if (isIE5 || isIE55 || isIE6 || isIE7) { objDiv.style.left = (pos.x) + "px"; } else { objDiv.style.left = (pos.x) + "px"; }
    }
    if (isIE5 || isIE55 || isIE6 || isIE7) { objDiv.style.top = (pos.y + 22) + "px"; } else { objDiv.style.top = (pos.y + 22) + "px"; }

    objDiv.style.display = "";
    document.ondblclick = function() { if (objDiv.style.display == "") { objDiv.style.display = "none"; } }
    document.body.appendChild(objDiv);
}


function closediv(objDiv) {
    objDiv.parentNode.removeChild(objDiv);
}

var LastSelectObj;
var LastSelectObj2;

function selectFile(type, obj,obj2, height, width) {
    var ShowObj = obj;
    if (isArray(obj) && obj.length > 1)
        ShowObj = obj[1];
    showfDiv(ShowObj, "loading...", width);
    LastSelectObj = obj;
    LastSelectObj2 = obj2;

    var options = {
        method: 'get',
        parameters: "heights=" + height,
        onComplete: function(transport) {
            var returnvalue = transport.responseText;
            if (returnvalue.indexOf("??") > -1)
                showfDiv(ShowObj, 'Error', width);
            else
                var tempstr = returnvalue;
            showfDiv(ShowObj, tempstr, width);
        }
    };
    var arrtype = type.split("|")[0]
    switch (arrtype) {

        case "UserListShow":
            new Ajax.Request('../CommonPage/iframe.aspx?FileType=UserListShow', options);
            break;
        case "UserlistShowRadio":
            new Ajax.Request('../CommonPage/iframe.aspx?FileType=UserlistShowRadio', options);
            break;
    }
}


function sFiles(obj) {
    document.Templetslist.sUrl.value = obj;
}

function ReturnFun2(Return_Strs1,Return_Strs2) {
    if (isArray(LastSelectObj)) {
        for (var i = 0; i < LastSelectObj.length; i++) {
            SetValue(LastSelectObj[i], Return_Strs1[i]);
        }
    }
    else {
        SetValue(LastSelectObj, Return_Strs1);
    }

    if (isArray(LastSelectObj2)) {
        for (var i = 0; i < LastSelectObj2.length; i++) {
            SetValue(LastSelectObj2[i], Return_Strs2[i]);
        }
    }
    else {
        SetValue(LastSelectObj2, Return_Strs2);
    }
    
    document.getElementById("s_id").style.display = "none";
}




function ReturnFun(Return_Strs) {
    if (isArray(LastSelectObj)) {
        for (var i = 0; i < LastSelectObj.length; i++) {
            SetValue(LastSelectObj[i], Return_Strs[i]);
        }
    }
    else {
        SetValue(LastSelectObj, Return_Strs);
    }
    document.getElementById("s_id").style.display = "none";
}

function SetValue(obj, val) {
    if (obj == null || typeof (obj) == "undefined") {
        alert("选择失败，请重新选择。");
    }
    else {
        if (val == null || typeof (val) == "undefined")
            val = '';
        obj.value = val;
    }
}

function ReturnTagsFun(Return_Strs) {
    var s = LastSelectObj.value
    if (typeof (LastSelectObj) == "undefined" || LastSelectObj == null) {
        alert("选择失败，请重新选择。");
    }
    else {
        if (s.indexOf(Return_Strs) == -1) {
            if (s == "") {
                LastSelectObj.value = Return_Strs;
            }
            else {
                LastSelectObj.value = s + "|" + Return_Strs;
            }
        }
    }
    document.getElementById("s_id").style.display = "none";
    return;
}


position = function(x, y) {
    this.x = x;
    this.y = y;
}

getPosition = function(oElement) {
    var objParent = oElement
    var oPosition = new position(0, 0);
    while (objParent.tagName != "BODY") {
        oPosition.x += objParent.offsetLeft;
        oPosition.y += objParent.offsetTop;
        objParent = objParent.offsetParent;
    }
    return oPosition;
}




function getOffsetLeft(elm) {
    var mOffsetLeft = elm.offsetLeft;
    var mOffsetParent = elm.offsetParent;
    while (mOffsetParent) {
        mOffsetLeft += mOffsetParent.offsetLeft;
        mOffsetParent = mOffsetParent.offsetParent;
    }
    return mOffsetLeft;
}
function getOffsetTop(elm) {
    var mOffsetTop = elm.offsetTop;
    var mOffsetParent = elm.offsetParent;
    while (mOffsetParent) {
        mOffsetTop += mOffsetParent.offsetTop;
        mOffsetParent = mOffsetParent.offsetParent;
    }
    return mOffsetTop;
}

drag = function(a, o) {
    var d = document; if (!a) a = window.event;
    if (!a.pageX) a.pageX = a.clientX;
    if (!a.pageY) a.pageY = a.clientY;
    var x = a.pageX, y = a.pageY;
    if (o.setCapture)
        o.setCapture();
    else if (window.captureEvents)
        window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
    var backData = { x: o.style.top, y: o.style.left };
    d.onmousemove = function(a) {
        if (!a) a = window.event;
        if (!a.pageX) a.pageX = a.clientX;
        if (!a.pageY) a.pageY = a.clientY;
        var tx = a.pageX - x + parseInt(o.style.left), ty = a.pageY - y + parseInt(o.style.top);
        o.style.left = tx + "px";
        o.style.top = ty + "px";
        x = a.pageX;
        y = a.pageY;
    };

    d.onmouseup = function(a) {
        if (!a) a = window.event;
        if (o.releaseCapture)
            o.releaseCapture();
        else if (window.captureEvents)
            window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
        d.onmousemove = null;
        d.onmouseup = null;
        if (!a.pageX) a.pageX = a.clientX;
        if (!a.pageY) a.pageY = a.clientY;
        if (!document.body.pageWidth) document.body.pageWidth = document.body.clientWidth;
        if (!document.body.pageHeight) document.body.pageHeight = document.body.clientHeight;
        if (a.pageX < 1 || a.pageY < 1 || a.pageX > document.body.pageWidth || a.pageY > document.body.pageHeight) {
            o.style.left = backData.y;
            o.style.top = backData.x;
        }
    };
}

//判断是否数组
function isArray(obj) {
    if (obj.constructor == window.Array)
        return true;
    else
        return false;
}


//画面弹出
function openwindow(url, name, iWidth, iHeight) {
    var url;                             //转向网页的地址;
    var name;                            //网页名称，可为空;
    var iWidth;                          //弹出窗口的宽度;
    var iHeight;                         //弹出窗口的高度;
    //获得窗口的垂直位置
    var iTop = (window.screen.availHeight - 30 - iHeight) / 2;
    //获得窗口的水平位置
    var iLeft = (window.screen.availWidth - 10 - iWidth) / 2;
    window.open(url, name, 'height=' + iHeight + ',,innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no');
}

//调用
//加载会员相关信息
function GetVipMemberList(UnionId) {
    var selectVipInfo;
    var queryString = "time=" + new Date() + "&TransFlg=VipMember" + "&FromSource=Organizations" + "&UnionId=" + UnionId;
    $.ajax
                    ({
                        async: false,
                        type: "post", //ajax请求方式
                        url: "../ajaxGetJason.aspx", //请求服务器地址
                        datatype: "json", //希望数据库返回的数据类型
                        data: queryString, //发送给服务器的数据
                        processData: false, //阻止数据被自动转换为url编码
                        success: function(data) {//请求成功则调用该函数
                            var temp = eval(data);
                            if (temp) {
                                $.each(temp, function(i, item) {
                                    selectVipInfo += "<option value=" + item["姓名"] + ">" + item["姓名"] + "</option>";
                                });
                            }
                        }
                    });
    return selectVipInfo;
}

//加载会员相关信息(Value值带用户ＩＤ)
function GetTheVipMemberList(UnionId) {
    var selectVipInfo;
    var queryString = "time=" + new Date() + "&TransFlg=VipMember" + "&FromSource=Organizations" + "&UnionId=" + UnionId;
    $.ajax
                    ({
                        async: false,
                        type: "post", //ajax请求方式
                        url: "../ajaxGetJason.aspx", //请求服务器地址
                        datatype: "json", //希望数据库返回的数据类型
                        data: queryString, //发送给服务器的数据
                        processData: false, //阻止数据被自动转换为url编码
                        success: function(data) {//请求成功则调用该函数
                            var temp = eval(data);
                            if (temp) {
                                $.each(temp, function(i, item) {
                                    selectVipInfo += "<option value=" + item["ID"] + ">" + item["姓名"] + "</option>";
                                });
                            }
                        }
                    });
    return selectVipInfo;
}

//加载单位相应的选项
function GetUionList() {
    var selectCompanyInfo = "";
    var queryString = "time=" + new Date() + "&TransFlg=UionList" + "&FromSource=Organizations";
    $.ajax
                    ({
                        async: false,
                        type: "post", //ajax请求方式
                        url: "../ajaxGetJason.aspx", //请求服务器地址
                        datatype: "json", //希望数据库返回的数据类型
                        data: queryString, //发送给服务器的数据
                        processData: false, //阻止数据被自动转换为url编码
                        success: function(data) {//请求成功则调用该函数
                            var temp = eval(data);
                            if (temp) {
                                $.each(temp, function(i, item) {
                                    selectCompanyInfo += "<option value=" + item["ID"] + ">" + item["单位名称"] + "</option>";
                                });
                            }
                        }
                    });
    return selectCompanyInfo;
}


//加载单位相应的选项
function GetUionListFirstId() {
    var selectCompanyInfo = "";
    var strFirstValue = "";
    var queryString = "time=" + new Date() + "&TransFlg=UionList" + "&FromSource=Organizations";
    $.ajax
                    ({
                        async: false,
                        type: "post", //ajax请求方式
                        url: "../ajaxGetJason.aspx", //请求服务器地址
                        datatype: "json", //希望数据库返回的数据类型
                        data: queryString, //发送给服务器的数据
                        processData: false, //阻止数据被自动转换为url编码
                        success: function(data) {//请求成功则调用该函数
                            var temp = eval(data);
                            if (temp) {
                                $.each(temp, function(i, item) {
                                    if (i == 0) {
                                        strFirstValue = item["ID"];
                                    }
                                });
                            }
                        }
                    });
     return strFirstValue;
}


//加载Select中Value内容
function SetSelectValue(strReplace, DefaultValue) {
    //可输入Select控件初始化
    var strSelectSoource = "<select style='width:98%;z-index:-1' name='tmpSel'    onkeydown=catch_keydown(this) onkeypress=catch_press(this) onfocus=catch_focus(this)><option selected='selected' value='@@'>@@@</option>@</select>";
    var SelectValue = ""
    SelectValue = strSelectSoource.replace("@@", DefaultValue).replace("@@@", DefaultValue).replace("@", strReplace);
    return SelectValue;
}

//加载不可以编辑的Select中Value内容
function SetDisEditSelectValue(strReplace) {
    //不可以输入的Select的初始化
    var strDisEditSelectSoource = "<select style='width:98%;z-index:-1' name='tmpSel'    onkeydown=catch_keydown(this) onkeypress=catch_press(this) onfocus=catch_focus(this)>@</select>";
    var SelectValue = ""
    SelectValue = strDisEditSelectSoource.replace("@", strReplace);
    return SelectValue;
}


function SetInputDefaultValue(DefaultValue, Length) {
    var strInput = "<input  type='text' style='width:90%' value='@' maxlength='@@' />";
    return strInput.replace('@', DefaultValue).replace('@@', Length);
}

function SetInputOnlyNumberDefaultValue(DefaultValue, Length) {
    var strInput = "<input  type='text' style='width:90%' value='@' class='onlynumber' maxlength='@@' />";
    return strInput.replace('@', DefaultValue).replace('@@', Length);
}


//加载员工登记的选项
function GetClassList(strStryle) {
    var selectClassiInfo = "";
    var queryString = "time=" + new Date() + "&TransFlg=Class" + "&Style=" + strStryle;
    $.ajax
                    ({
                        async: false,
                        type: "post", //ajax请求方式
                        url: "../ajaxGetJason.aspx", //请求服务器地址
                        datatype: "json", //希望数据库返回的数据类型
                        data: queryString, //发送给服务器的数据
                        processData: false, //阻止数据被自动转换为url编码
                        success: function(data) {//请求成功则调用该函数
                            var temp = eval(data);
                            if (temp) {
                                $.each(temp, function(i, item) {
                                selectClassiInfo += "<option value=" + item["小区分"] + ">" + item["区分名称"] + "</option>";
                                });
                            }
                        }
                    });
     return selectClassiInfo;
 }

 //加载员工登记的选项
 function GetSexList() {
     var selectClassiInfo = "";
    selectClassiInfo += "<option value='0'>" + "男" + "</option>";
    selectClassiInfo += "<option value='1'>" + "女" + "</option>";
    return selectClassiInfo;
}
 
 
 //保留小数点两位
 function   FormatNumber(srcStr)
{
　
    var a = srcStr * 100;
    
    var i = a.toString().indexOf(".");
    if (i == -1) {
        return a + "." + "0%";
    }
    else {
        //alert("100X" + a);
        //alert("整数部门" + a.toString().substring(0, i));
        //alert("小数部门" + a.toString().substring(i + 1, i + 2));
        var a0 = a.toString().substring(0, i);
        var a1 = a.toString().substring(i + 1, i + 2);
        var a2 = a0 + "." + a1;
        return a2 + "%";
    }
}



//加载员工登记的选项
function GetYesNoName(strOption) {
    if (strOption == "0") {
        return "否";

    }
    else {
        return "是"; 
    }
}

//只能输入数字
function KeyPressOnlyNumber() {
    var keyCode = event.keyCode;
    if ((keyCode >= 48 && keyCode <= 57)) {
        event.returnValue = true;
    } else {
        event.returnValue = false;
    }
}

function strToNum(strNum) {
    var intReturnValue = 0;
    if (strNum == "") return 0;
    return parseInt(strNum);
}

//验证数字
function isNumber(oNum) {
    if (oNum == "") return true;
    if (!oNum) return false;
    var strP = /^\d+(\.\d+)?$/;
    if (!strP.test(oNum)) return false;
    try {
        if (parseFloat(oNum) != oNum) return false;
    }
    catch (ex) {
        return false;
    }
    return true;
}

function strToint(strValue) {
    if (strValue == "") return 0;
    return parseInt(strValue);
}

//判断日期类型是否为YYYY-MM-DD格式的类型
function IsDate(strDate) {     
     if (strDate.length != 0) {    
        var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
        var r = strDate.match(reg);
        if (r == null) {
            return false;  
        }
      }
    return true;
}    

//判断类型是否百分比
function IsPercent(strPercent) {
    if (strPercent.length != 0) {
        //var reg = /^\d+(\.\d+)?%$/;
        var reg = /^((100(\.0)?)|((\d|[1-9]\d)(\.\d{1})?))$/;
        var r = strPercent.match(reg);
        if (r == null) {
            return false;  
        }
      }
    return true;
}    
